/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package CapaSecretaria;

import Capamixta.MainMenu;
import capanegocio.itinerario;
import capanegocio.pasajero;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Seralan
 */
public class cliente extends javax.swing.JFrame {

    /**
     * Creates new form cliente
     */
    pasajero p;
    itinerario i;
    
    int contador=0;
    public cliente() {
        initComponents();
        p=new pasajero();
        i= new itinerario();
        setResizable(false);//metodo que no permite la maximizacion
        setLocationRelativeTo(null);//cuando se abra la ventana se abre en el centro de la pantalla
        setTitle("Clientes");//para darle nombre a la ventana
        setSize(800, 600);//Tamaño de la ventana
        school.removeAll();
        buses.removeAll();
        Combobox();
        Combobox2();
        updateTabla();
    }
    public void Combobox(){
        
        try{
        Connection c=DriverManager.getConnection("jdbc:mysql://localhost/agua_azul","root","");
        Statement sent=c.createStatement();
        ResultSet rs= sent.executeQuery("Select Nombre_Colegio from colegio");
        while (rs.next()){
            this.school.addItem(rs.getString("Nombre_Colegio"));
        }
        contador++;
    }catch (Exception e){
            JOptionPane.showMessageDialog(null, e);
            }
        
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    public void Combobox2(){
        
        try{
        Connection c=DriverManager.getConnection("jdbc:mysql://localhost/agua_azul","root","");
        Statement sent=c.createStatement();
        ResultSet rs= sent.executeQuery("Select Pantente from bus");
        while (rs.next()){
            this.buses.addItem(rs.getString("Pantente"));
        }
        contador++;
    }catch (Exception e){
            JOptionPane.showMessageDialog(null, e);
            }
        
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nombre_pasajero = new javax.swing.JTextField();
        jLabelnombrepa = new javax.swing.JLabel();
        jLabelapellidopa = new javax.swing.JLabel();
        jLabelrutpa = new javax.swing.JLabel();
        jLabeldomiciliopa = new javax.swing.JLabel();
        apellido_pasajero = new javax.swing.JTextField();
        jButtoncerrar = new javax.swing.JButton();
        jLabelapoderado = new javax.swing.JLabel();
        jLabeldatoscliente = new javax.swing.JLabel();
        jLabelcolegiopa = new javax.swing.JLabel();
        jLabelnombreappa = new javax.swing.JLabel();
        jLabelpasajero = new javax.swing.JLabel();
        jScrollPanelingreso = new javax.swing.JScrollPane();
        tabla_pasajero = new javax.swing.JTable();
        jLabelvalor = new javax.swing.JLabel();
        jButtonActualizar = new javax.swing.JButton();
        jButtonAgregar = new javax.swing.JButton();
        jseparador = new javax.swing.JSeparator();
        apoderado_pasajero = new javax.swing.JTextField();
        domicilio_pasajero = new javax.swing.JTextField();
        rut_pasajero = new javax.swing.JTextField();
        codigo_colegio = new javax.swing.JTextField();
        terminal_pasajero = new javax.swing.JLabel();
        school = new javax.swing.JComboBox();
        valor_colegio = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        hora_salida = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        minutos_salida = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        minutos_llegada = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        hora_llegada = new javax.swing.JTextField();
        txtbuses = new javax.swing.JTextField();
        jMenuBar1 = new javax.swing.JMenuBar();
        colegios = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        Salir = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabelnombrepa.setText("Nombre");

        jLabelapellidopa.setText("Apellidos");

        jLabelrutpa.setText("Rut");

        jLabeldomiciliopa.setText("Domicilio");

        jButtoncerrar.setText("Borrar Cliente");
        jButtoncerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtoncerrarActionPerformed(evt);
            }
        });

        jLabelapoderado.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabelapoderado.setText("Apoderado");

        jLabeldatoscliente.setFont(new java.awt.Font("Tahoma", 3, 24)); // NOI18N
        jLabeldatoscliente.setText("Datos Cliente");

        jLabelcolegiopa.setText("Colegio");

        jLabelnombreappa.setText("Nombre/Apellido");

        jLabelpasajero.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabelpasajero.setText("Pasajero");

        tabla_pasajero.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Rut", "Nombre", "Apellido ", "Colegio", "Apoderado", "Domicilio"
            }
        ));
        tabla_pasajero.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabla_pasajeroMouseClicked(evt);
            }
        });
        jScrollPanelingreso.setViewportView(tabla_pasajero);

        jLabelvalor.setText("Valor :");

        jButtonActualizar.setText("Actualizar Cliente");
        jButtonActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonActualizarActionPerformed(evt);
            }
        });

        jButtonAgregar.setText("Agregar Cliente");
        jButtonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAgregarActionPerformed(evt);
            }
        });

        school.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                schoolActionPerformed(evt);
            }
        });

        valor_colegio.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setText("$");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Buses y Recorrido");

        jLabel3.setText("Seleccione Bus");

        jLabel4.setText("Hora Salida (HH:MM) :");

        jLabel5.setText(":");

        jLabel6.setText("Hora Llegada (HH:MM) :");

        jLabel7.setText(":");

        colegios.setText("Menus");
        colegios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                colegiosActionPerformed(evt);
            }
        });

        jMenuItem1.setText("Colegios");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        colegios.add(jMenuItem1);

        jMenuItem3.setText("Registro Pagos");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        colegios.add(jMenuItem3);

        jMenuItem4.setText("Registro Itinerarios");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        colegios.add(jMenuItem4);

        Salir.setText("Salir");
        Salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SalirActionPerformed(evt);
            }
        });
        colegios.add(Salir);

        jMenuBar1.add(colegios);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelpasajero)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelnombrepa)
                            .addComponent(jLabelapellidopa)
                            .addComponent(jLabelrutpa)
                            .addComponent(jLabeldomiciliopa)
                            .addComponent(jLabelcolegiopa))
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(domicilio_pasajero, javax.swing.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
                            .addComponent(rut_pasajero)
                            .addComponent(apellido_pasajero)
                            .addComponent(nombre_pasajero)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(codigo_colegio, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(school, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelapoderado)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelnombreappa)
                        .addGap(30, 30, 30)
                        .addComponent(apoderado_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabelvalor)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(valor_colegio, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(98, 98, 98)
                        .addComponent(txtbuses, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(hora_salida, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(minutos_salida, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(hora_llegada, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(minutos_llegada, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(34, 34, 34))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jScrollPanelingreso))
                    .addComponent(jseparador, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(terminal_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, 519, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(80, 80, 80)
                                .addComponent(jButtonAgregar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonActualizar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtoncerrar)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(293, 293, 293)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabeldatoscliente, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(279, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabeldatoscliente)
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelpasajero)
                    .addComponent(jLabelapoderado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombre_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelnombrepa)
                    .addComponent(jLabelnombreappa)
                    .addComponent(apoderado_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(apellido_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabelapellidopa))
                            .addComponent(valor_colegio, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(rut_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelrutpa))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(domicilio_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabeldomiciliopa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(codigo_colegio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabelcolegiopa)
                                    .addComponent(school, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(2, 2, 2))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(hora_llegada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel7)
                                        .addComponent(minutos_llegada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jLabel6)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelvalor)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtbuses, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(hora_salida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(minutos_salida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonActualizar)
                    .addComponent(jButtonAgregar)
                    .addComponent(jButtoncerrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jseparador, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPanelingreso, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45)
                .addComponent(terminal_pasajero, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(41, 41, 41))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtoncerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtoncerrarActionPerformed
        p.deletePasajero(rut_pasajero.getText());
        limpiar();
        updateTabla();
        terminal_pasajero.setText("Pasajero Eliminado Satisfactoriamente");
    }//GEN-LAST:event_jButtoncerrarActionPerformed

    private void jButtonAgregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAgregarActionPerformed
       p.newPasajero(rut_pasajero.getText(),Integer.parseInt(codigo_colegio.getText()), nombre_pasajero.getText() , apellido_pasajero.getText(), apoderado_pasajero.getText(), domicilio_pasajero.getText());
       i.newItinerario(txtbuses.getText(), rut_pasajero.getText(), hora_salida.getText()+":"+minutos_salida.getText(), hora_llegada.getText()+":"+minutos_llegada.getText());
       terminal_pasajero.setText("Pasajero Agregado Satisfactoriamente");
       updateTabla();
    }//GEN-LAST:event_jButtonAgregarActionPerformed

    private void jButtonActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonActualizarActionPerformed
      p.updatePasajero(rut_pasajero.getText(),Integer.parseInt(codigo_colegio.getText()), nombre_pasajero.getText() , apellido_pasajero.getText(), apoderado_pasajero.getText(), domicilio_pasajero.getText());
      terminal_pasajero.setText("Pasajero Editado Satisfactoriamente");
      updateTabla();
    }//GEN-LAST:event_jButtonActualizarActionPerformed

    private void tabla_pasajeroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabla_pasajeroMouseClicked
        fila = tabla_pasajero.rowAtPoint(evt.getPoint());                 
         if (fila > -1){  
             rut_pasajero.setText(String.valueOf(tabla_pasajero.getValueAt(fila, 0)));
             codigo_colegio.setText(String.valueOf(tabla_pasajero.getValueAt(fila, 1)));
             nombre_pasajero.setText(String.valueOf(tabla_pasajero.getValueAt(fila, 2)));
             apellido_pasajero.setText(String.valueOf(tabla_pasajero.getValueAt(fila, 3)));
             apoderado_pasajero.setText(String.valueOf(tabla_pasajero.getValueAt(fila, 4)));
             domicilio_pasajero.setText(String.valueOf(tabla_pasajero.getValueAt(fila, 5)));
            try {
                Connection c=DriverManager.getConnection("jdbc:mysql://localhost/agua_azul","root","");
                Statement sent=c.createStatement();
                ResultSet rs= sent.executeQuery("Select Nombre_Colegio from colegio where Codigo_Colegio = '"+String.valueOf(this.codigo_colegio.getText())+"'");
                rs.next();
                this.school.setSelectedItem(rs.getString("Nombre_Colegio"));
            } catch (SQLException ex) {
                Logger.getLogger(cliente.class.getName()).log(Level.SEVERE, null, ex);
            }
            
                         
          }
    }//GEN-LAST:event_tabla_pasajeroMouseClicked

    private void colegiosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_colegiosActionPerformed
        
    }//GEN-LAST:event_colegiosActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        colegios obj=new colegios(); //creacion de nuevo objeto o frame
        obj.setVisible(true);// visible nuevo frame (colegios ej)
        dispose();//cierra ventana actual 
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void schoolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schoolActionPerformed
    if(contador>0){
        try{
        Connection c1=DriverManager.getConnection("jdbc:mysql://localhost/agua_azul","root","");
        Statement sent1=c1.createStatement();
        ResultSet rs1=sent1.executeQuery("select Codigo_Colegio from colegio where Nombre_Colegio ='"+this.school.getSelectedItem()+"'");
        rs1.next();
        this.codigo_colegio.setText(String.valueOf(rs1.getInt("Codigo_Colegio")));
        ResultSet rs2=sent1.executeQuery("select Valor_Colegio from colegio where Nombre_Colegio ='"+this.school.getSelectedItem()+"'");
        rs2.next();
        this.valor_colegio.setText(String.valueOf(rs2.getInt("Valor_Colegio")));
    }catch(Exception e){
        JOptionPane.showMessageDialog(null, e);
    }
    }//GEN-LAST:event_schoolActionPerformed
    }
    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
         Pagos obj=new Pagos(); //creacion de nuevo objeto o frame
        obj.setVisible(true);// visible nuevo frame (colegios ej)
        dispose();//cierra ventana actual 
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        itinerarios obj=new itinerarios(); //creacion de nuevo objeto o frame
        obj.setVisible(true);// visible nuevo frame (colegios ej)
        dispose();//cierra ventana actual 
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void SalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SalirActionPerformed
        MainMenu obj=new MainMenu(); //creacion de nuevo objeto o frame
        obj.setVisible(true);// visible nuevo frame (colegios ej)
        dispose();//cierra ventana actual        // TODO add your handling code here:
    }//GEN-LAST:event_SalirActionPerformed
   
    public void limpiar(){
        nombre_pasajero.setText("");
        rut_pasajero.setText("");
        codigo_colegio.setText("");
        apellido_pasajero.setText("");
        apoderado_pasajero.setText("");
        domicilio_pasajero.setText(""); 
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(cliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new cliente().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem Salir;
    private javax.swing.JTextField apellido_pasajero;
    private javax.swing.JTextField apoderado_pasajero;
    private javax.swing.JTextField codigo_colegio;
    private javax.swing.JMenu colegios;
    private javax.swing.JTextField domicilio_pasajero;
    private javax.swing.JTextField hora_llegada;
    private javax.swing.JTextField hora_salida;
    private javax.swing.JButton jButtonActualizar;
    private javax.swing.JButton jButtonAgregar;
    private javax.swing.JButton jButtoncerrar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelapellidopa;
    private javax.swing.JLabel jLabelapoderado;
    private javax.swing.JLabel jLabelcolegiopa;
    private javax.swing.JLabel jLabeldatoscliente;
    private javax.swing.JLabel jLabeldomiciliopa;
    private javax.swing.JLabel jLabelnombreappa;
    private javax.swing.JLabel jLabelnombrepa;
    private javax.swing.JLabel jLabelpasajero;
    private javax.swing.JLabel jLabelrutpa;
    private javax.swing.JLabel jLabelvalor;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JScrollPane jScrollPanelingreso;
    private javax.swing.JSeparator jseparador;
    private javax.swing.JTextField minutos_llegada;
    private javax.swing.JTextField minutos_salida;
    private javax.swing.JTextField nombre_pasajero;
    private javax.swing.JTextField rut_pasajero;
    private javax.swing.JComboBox school;
    private javax.swing.JTable tabla_pasajero;
    private javax.swing.JLabel terminal_pasajero;
    private javax.swing.JTextField txtbuses;
    private javax.swing.JLabel valor_colegio;
    // End of variables declaration//GEN-END:variables
Object [][] dtPer;
    int fila=-1;
    //mostrar datos de colegios desde la base de datos
    private void updateTabla(){
        String [] ColumnNames={"Rut","Cod Colegio", "Nombre","Apellido","Apoderado" ,"Direccion"};
        dtPer=p.getDatos();
        DefaultTableModel Datos=new DefaultTableModel(dtPer,ColumnNames);
        tabla_pasajero.setModel(Datos);
        TableColumn columna=tabla_pasajero.getColumn("Rut");
        }
        
    }
